package api;

import utils.CommUtils;
import utils.HttpUtils;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

/**
 * 企业核验API接口
 */
public class EnterpriseApi extends AccessToken {
    private final static String epElem3URI = "/aip/check/v1/ep/elem3";
    private final static String epElem4URI = "/aip/check/v1/ep/elem4";

    private final static String epElem4FRURI = "/aip/check/v1/ep/elem4fr";

    /**
     * 1.企业三要素核验
     */
    public static void epElem3(String _BizNo, String companyName, String creditCode, String legalPerson) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("companyName", companyName);
        paramsMap.put("creditCode", creditCode);
        paramsMap.put("legalPerson", legalPerson);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, epElem3URI, getCachedAccessToken(), paramsMap);
        System.out.println("企业三要素核验-- >> epElem3:" + res);
    }

    /**
     * 2.企业四要素（营业期限）核验
     */
    public static void epElem4(String _BizNo, String companyName, String creditCode, String legalPerson, String startPeriod, String endPeriod) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("companyName", companyName);
        paramsMap.put("creditCode", creditCode);
        paramsMap.put("legalPerson", legalPerson);
        paramsMap.put("startPeriod", startPeriod);
        paramsMap.put("endPeriod", endPeriod);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, epElem4URI, getCachedAccessToken(), paramsMap);
        System.out.println("企业四要素核验-- >> epElem4:" + res);

    }


    /**
     * 3.企业四要素（法人）核验
     */
    public static void epElem4FR(String _BizNo, String companyName, String creditCode, String legalPerson, String idNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("companyName", companyName);
        paramsMap.put("creditCode", creditCode);
        paramsMap.put("legalPerson", legalPerson);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, epElem4FRURI, getCachedAccessToken(), paramsMap);
        System.out.println("企业四要素（法人）核验-- >> epElem4FR:" + res);

    }


    public static void main(String[] args) {
        //1.企业三要素核验
        epElem3(UUID.randomUUID().toString(), "A公司", "4408041880060xxxx", "李四");

        //2.企业四要素（营业期限）核验
        epElem4(UUID.randomUUID().toString(), "A公司", "4408041880060xxxx", "李四", "2020-01-01 00:00:00", "2024-01-01 00:00:00");

        //3.企业四要素（法人）核验
        epElem4FR(UUID.randomUUID().toString(), "A公司", "4408041880060xxxx", "李四", "4408041880060xxxx");

    }

}
